package protocol.transactions;

import protocol.XoneProtocol;
import protocol.XoneServiceCode;

import com.google.gson.JsonElement;
import com.netease.http.THttpRequest;

public class TransactionUnReadInfoCount extends XoneBaseTransaction {

    public TransactionUnReadInfoCount() {
        super(TRANSACTION_TYPE_GETUNREADINFOCOUNT);
    }

    @Override
    protected void onXoneTransactionSuccess(int code, Object obj) {
        if (obj instanceof JsonElement) {
            int count = 0;
            try {
                count = ((JsonElement)obj).getAsJsonObject().get("count").getAsInt();
            } catch (Exception e) {
                e.printStackTrace();
            }
            notifyMessage(XoneServiceCode.TRANSACTION_SUCCESS, count);
        }
        
    }

    @Override
    public void onTransact() {
        THttpRequest request = XoneProtocol.getInstance().createUnReadInfoCount();
        sendRequest(request);
    }
}
